// pages/report/search/search.js
const api=require('../../../utils/request')

Page({

  /**
   * 页面的初始数据
   */
  data: {
     searchValue:'',
     mySearchData:[],
     tipShow:true,
     otherSearchData:[]
  },
//取消
cancle(){
wx.navigateBack({
  delta:1
})
},
close(){
  this.setData({
    tipShow:false
  });
},
bindconfirm(){
     this.search()
},
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.loadData()
  },
  searchImage(e){
      console.log('sssss',e)
      wx.navigateTo({
        url: '../search_res/searchc_res?searchInput='+e.currentTarget.dataset.id,
      })
  },
loadData(){
    let userInfo= wx.getStorageSync('user')
    let user= JSON.parse(userInfo) 
    let that=this
    api.get('weChatMini/findSearch/'+user.id).then(response=>{
         
        if(response.code===200){
            if(response.data.list!==null){
                  that.setData({
                    mySearchData:response.data.list
                  })
            }

            if(response.data.lists1!=null){
                that.setData({
                    otherSearchData:response.data.lists1
                  })
            }

        }
    })
},

  search(){
      
let userInfo= wx.getStorageSync('user')

  if(this.data.searchValue!==''){
      let memberId=''
  if(userInfo!==''){
    let user= JSON.parse(userInfo) 
    memberId=user.id
  }else{
      memberId=''
  }
  
    api.post('weChatMini/saveSearch',{name:this.data.searchValue,memberId:memberId}).then(res=>{
        if(res.code===200){
            wx.navigateTo({
                url: '../search_res/searchc_res?searchInput='+this.data.searchValue,
              })
        }
    })  
  }else{
    wx.navigateTo({
        url: '../search_res/searchc_res?searchInput='+this.data.searchValue,
      })
  }
    
   
  },
  clealSearch(){
    
      let userInfo= wx.getStorageSync('user')
      let user= JSON.parse(userInfo) 
      let that=this
      api.get('weChatMini/clearSearch/'+user.id).then(response=>{
          if(response.code===200){
            that.setData({
                mySearchData: []
            })
          }else{

          }
      })
  },
  searchInput(e){
console.log('eee',e)
this.setData({
    searchValue: e.detail.value
})
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})